/**
  author: kevin
 */
package web

import (
	"net/http"
	"fmt"
	"dooms/supplychain/web/controller"
	"strconv"
)

func  WebStart(app *controller.Application, port int)  {

	fs := http.FileServer(http.Dir("web/static"))
	http.Handle("/static/", http.StripPrefix("/static/", fs))

	http.HandleFunc("/", app.QueryOrderView)
	http.HandleFunc("/index.html", app.QueryOrderView)
	http.HandleFunc("/queryOrder", app.QueryOrder)
	http.HandleFunc("/changeOrder", app.ChangeOrder)
	http.HandleFunc("/changeOrderSend", app.ChangeOrderSend)
	http.HandleFunc("/changeOrderRecv", app.ChangeOrderRecv)
	http.HandleFunc("/changeOrderRecv1", app.ChangeOrderRecv1)
	http.HandleFunc("/requestloan.html", app.RequestLoanView)
	http.HandleFunc("/requestloan", app.RequestLoan)
	http.HandleFunc("/loan.html", app.LoanView)
	http.HandleFunc("/loan", app.Loan)
	http.HandleFunc("/setquota.html", app.SetQuotaView)
	http.HandleFunc("/setquota", app.SetQuota)
	http.HandleFunc("/queryhistory.html", app.QueryHistoryView)
	http.HandleFunc("/queryhistory", app.QueryHistory)
	http.HandleFunc("/upload.html", app.UpLoadView)
	http.HandleFunc("/download", app.DownloadPicture)

	fmt.Println("启动Web服务, 监听端口号: " + strconv.Itoa(port))

	listenAddr := ":" + strconv.Itoa(port)
	err := http.ListenAndServe(listenAddr, nil)
	if err != nil {
		fmt.Println("启动Web服务错误")
	}

}